package com.xintonghua.base.utils;


import android.annotation.SuppressLint;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.Locale;

public class MyTimeUtils {

    /**
     * 验证是否过了有效期
     *
     * @param time
     * @return
     */
    public static boolean notOutTime(String time) {
        long inputTime = getYYMMDDHHMMSSLByString(time);
        if (inputTime < getNowTimeMillis()) {
            return false;
        } else {
            return true;
        }
    }

    public static Date getData(long m) {
        Date date = new Date(m);
        return date;
    }

    public static String getHHMM(String time) {
        long aTime = getYYMMDDHHMMSSLByString(time);
        SimpleDateFormat format = new SimpleDateFormat("HH:mm");
        return format.format(aTime);
    }

    public static String getYYMMDD(String time) {
        long aTime = getYYMMDDLByString(time);
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
        return format.format(aTime);
    }

    /**
     * 获取系统当前时间的毫秒值
     *
     * @return
     */
    public static long getNowTimeMillis() {
        Date dt = new Date();
        Long time = dt.getTime();
        return time;
    }

    /**
     * 将date转化为毫秒值
     *
     * @param date
     * @return
     */
    public static long getTimeMillisByDate(Date date) {
        return date.getTime();
    }

    /**
     * 一天的时间的毫秒值
     *
     * @return
     */
    public static long getOneDayTimeMills() {
        long time;
        time = 24 * 60 * 60 * 1000;
        return time;
    }

    public static long getHourTimeMills() {
        long time;
        time = 60 * 60 * 1000;
        return time;
    }

    public static long getMinuteTimeMills() {
        long time;
        time = 60 * 1000;
        return time;
    }

    public static long getSecondTimeMills() {
        long time;
        time = 1000;
        return time;
    }


    /**
     * 获取系统当前时间的年月日
     *
     * @return
     */
    public static String getSystemYYMMDDX() {
        Date dt = new Date();
        SimpleDateFormat format = new SimpleDateFormat("yyyy/MM/dd");
        String time = format.format(dt.getTime());
        return time;//2015-10-03
    }

    /**
     * 获取系统当前时间的年月日 小时分钟
     *
     * @return
     */
    public static String getSystemYYMMDDHHMMX() {
        Date dt = new Date();
        SimpleDateFormat format = new SimpleDateFormat("yyyy/MM/dd HH:mm");
        String time = format.format(dt.getTime());
        return time;//2015-10-03 11:20
    }


    /**
     * 获取系统当前时间的年月日
     *
     * @return
     */
    public static String getSystemYYMMDDL() {
        Date dt = new Date();
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
        String time = format.format(dt.getTime());
        return time;//2015-10-03
    }

    /**
     * 获取系统当前时间的年月日 小时分钟
     *
     * @return
     */
    public static String getSystemYYMMDDHHMML() {
        Date dt = new Date();
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm");
        String time = format.format(dt.getTime());
        return time;//2015-10-03 11:20
    }

    public static String getSystemYYMMDDHHMMSSL() {
        Date dt = new Date();
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String time = format.format(dt.getTime());
        return time;//2015-10-03 11:20
    }

    /**
     * 获取系统当前时间的年月日
     *
     * @return
     */
    public static String getSystemYYMMDDP() {
        Date dt = new Date();
        SimpleDateFormat format = new SimpleDateFormat("yyyy.MM.dd");
        String time = format.format(dt.getTime());
        return time;//2015-10-03
    }

    /**
     * 获取系统当前时间的年月日 小时分钟
     *
     * @return
     */
    public static String getSystemYYMMDDHHMMP() {
        Date dt = new Date();
        SimpleDateFormat format = new SimpleDateFormat("yyyy.MM.dd HH:mm");
        String time = format.format(dt.getTime());
        return time;//2015-10-03 11:20
    }


    /**
     * 得到系统时间是一年中的第几周
     *
     * @return
     */
    public static int getCurrentWeeks() {
        Calendar calendar = Calendar.getInstance();
        int CurrentWeeks = calendar.get(Calendar.WEEK_OF_YEAR);
        return CurrentWeeks;
    }

    /**
     * 获取系统时间当前年
     *
     * @return
     */
    public static int getCurrentYear() {
        Calendar calendar = Calendar.getInstance();
        int CurrentYear = calendar.get(Calendar.YEAR);
        return CurrentYear;
    }

    /**
     * 得到系统时间是一年中的第几月
     *
     * @return
     */
    public static int getCurrentMonths() {
        Calendar calendar = Calendar.getInstance();
        int CurrentMonths = calendar.get(Calendar.MONTH);
        return CurrentMonths;
    }

    /**
     * 获取系统当天是月的第几天
     *
     * @return
     */
    public static int getCurrentDay() {
        Calendar calendar = Calendar.getInstance();
        int CurrentMonths = calendar.get(Calendar.DATE);
        return CurrentMonths;
    }

    /**
     * 获取系统时间当前小时数
     *
     * @return
     */
    public static int getCurrentHour() {
        Calendar calendar = Calendar.getInstance();
        int CurrentMonths = calendar.get(Calendar.HOUR_OF_DAY);
        return CurrentMonths;
    }

    /**
     * 获取系统时间当前分钟数
     *
     * @return
     */
    public static int getCurrentMinute() {
        Calendar calendar = Calendar.getInstance();
        int CurrentMonths = calendar.get(Calendar.MINUTE);
        return CurrentMonths;
    }


    /**
     * 得到传入时间的年份
     *
     * @param time
     * @return 年
     */
    public static int getYear(long time) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(new Date(time));
        return calendar.get(Calendar.YEAR);
    }

    /**
     * 得到传入时间的月份
     *
     * @param time
     * @return 月
     */
    public static int getMonth(long time) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(new Date(time));
        return calendar.get(Calendar.MONTH) + 1;
    }

    /**
     * 得到这个时间戳在当月的号数
     *
     * @return 这个月的第几日
     */
    public static int getDayOfMonth(long time) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(new Date(time));
        return calendar.get(Calendar.DAY_OF_MONTH);
    }

    /**
     * 得到这个时间戳在当年的号数
     *
     * @return 当年的第几日
     */
    public static int getDayOfYear(long time) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(new Date(time));
        return calendar.get(Calendar.DAY_OF_YEAR);
    }


    /**
     * 得到这个时间戳是周几
     *
     * @return
     */
    public static String getDayOfWeeks(long time) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTimeInMillis(time);
        int weekDay = calendar.get(Calendar.DAY_OF_WEEK);
        if (weekDay == Calendar.MONDAY)
            return "星期一";
        else if (weekDay == Calendar.TUESDAY)
            return "星期二";
        else if (weekDay == Calendar.WEDNESDAY)
            return "星期三";
        else if (weekDay == Calendar.THURSDAY)
            return "星期四";
        else if (weekDay == Calendar.FRIDAY)
            return "星期五";
        else if (weekDay == Calendar.SATURDAY)
            return "星期六";
        else if (weekDay == Calendar.SUNDAY)
            return "星期日";
        return "";
    }

    /**
     * 得到这个时间戳是当天的第几个小时
     *
     * @param time
     * @return
     */
    public static int getHourOfDay(long time) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(new Date(time));
        return calendar.get(Calendar.HOUR_OF_DAY);
    }

    /**
     * 得到传入的时间戳判断是否是今天
     *
     * @param time
     * @return
     */
    public static boolean isToday(long time) {
        SimpleDateFormat format = new SimpleDateFormat("yyyy/MM/dd");
        Date dt = new Date();
        String today = format.format(dt.getTime());

        String date = format.format(time);
        if (today.equals(date)) {
            return true;
        } else {
            return false;
        }
    }

    /**
     * 得到某年某月这个月的总天数
     *
     * @return 这个月的天数
     */
    public static int getAllDayOfMonth(int year, int month) {
        Calendar calendar = Calendar.getInstance();
        calendar.set(Calendar.YEAR, year);
        calendar.set(Calendar.MONTH, month - 1);
        calendar.set(Calendar.DATE, 1);
        calendar.roll(Calendar.DATE, -1);
        return calendar.get(Calendar.DATE);
    }

    /**
     * 根据年月日获得最小时间戳
     *
     * @param year
     * @param month
     * @param day
     * @return 当天最小的时间值
     */
    public static long getMinTimeByYMD(int year, int month, int day) {
        Calendar calendar = Calendar.getInstance();
        calendar.set(Calendar.YEAR, year);
        calendar.set(Calendar.MONTH, month - 1);
        calendar.set(Calendar.DATE, day);
        calendar.set(Calendar.HOUR_OF_DAY, calendar.getMinimum(Calendar.HOUR_OF_DAY));
        calendar.set(Calendar.MINUTE, calendar.getMinimum(Calendar.MINUTE));
        calendar.set(Calendar.SECOND, calendar.getMinimum(Calendar.SECOND));
        calendar.set(Calendar.MILLISECOND, calendar.getMinimum(Calendar.MILLISECOND));
        return calendar.getTimeInMillis();
    }

    /**
     * 根据年月日获得最大时间戳
     *
     * @param year
     * @param month
     * @param day
     * @return 当天最大的时间值
     */
    public static long getMaxTimeByYMD(int year, int month, int day) {
        Calendar calendar = Calendar.getInstance();
        calendar.set(Calendar.YEAR, year);
        calendar.set(Calendar.MONTH, month - 1);
        calendar.set(Calendar.DATE, day);
        calendar.set(Calendar.HOUR_OF_DAY, calendar.getMaximum(Calendar.HOUR_OF_DAY));
        calendar.set(Calendar.MINUTE, calendar.getMaximum(Calendar.MINUTE));
        calendar.set(Calendar.SECOND, calendar.getMaximum(Calendar.SECOND));
        calendar.set(Calendar.MILLISECOND, calendar.getMaximum(Calendar.MILLISECOND));
        return calendar.getTimeInMillis();
    }


    /**
     * 根据年月日某时某分获取毫秒值
     *
     * @param year
     * @param month
     * @param day
     * @return
     */
    public static long getDayTime(int year, int month, int day, int hour, int minute) {
        Calendar calendar = Calendar.getInstance();
        calendar.set(Calendar.YEAR, year);
        calendar.set(Calendar.MONTH, month - 1);
        calendar.set(Calendar.DATE, day);
        calendar.set(Calendar.HOUR_OF_DAY, hour);
        calendar.set(Calendar.MINUTE, minute);
        return calendar.getTimeInMillis();
    }


    /**
     * 获取今天最早的时刻
     *
     * @return
     */
    public static long getNowDayMinTime() {
        Calendar calendar = Calendar.getInstance();
        GregorianCalendar gregorianCalendar = new GregorianCalendar();
        gregorianCalendar.clear();
        gregorianCalendar.setTime(calendar.getTime());
        gregorianCalendar.set(Calendar.HOUR_OF_DAY, calendar.getMinimum(Calendar.HOUR_OF_DAY));
        gregorianCalendar.set(Calendar.MINUTE, calendar.getMinimum(Calendar.MINUTE));
        gregorianCalendar.set(Calendar.SECOND, calendar.getMinimum(Calendar.SECOND));
        gregorianCalendar.set(Calendar.MILLISECOND, calendar.getMinimum(Calendar.MILLISECOND));
        return gregorianCalendar.getTimeInMillis();
    }

    /**
     * 获取今天最后的时刻
     *
     * @return
     */
    public static long getNowDayMaxTime() {
        Calendar calendar = Calendar.getInstance();
        GregorianCalendar gregorianCalendar = new GregorianCalendar();
        gregorianCalendar.clear();
        gregorianCalendar.setTime(calendar.getTime());
        gregorianCalendar.set(Calendar.HOUR_OF_DAY, calendar.getMaximum(Calendar.HOUR_OF_DAY));
        gregorianCalendar.set(Calendar.MINUTE, calendar.getMaximum(Calendar.MINUTE));
        gregorianCalendar.set(Calendar.SECOND, calendar.getMaximum(Calendar.SECOND));
        gregorianCalendar.set(Calendar.MILLISECOND, calendar.getMaximum(Calendar.MILLISECOND));
        return gregorianCalendar.getTimeInMillis();
    }


    /**
     * 根据时间戳得到年月日格式的时间
     *
     * @param time 需要格式化的时间戳
     * @return
     */
    public static String getYYMMDDP(long time) {
        SimpleDateFormat format = new SimpleDateFormat("yyyy.MM.dd", Locale.getDefault());
        return format.format(time);
    }


    /**
     * 根据时间戳得到年月日小时分钟格式的时间
     *
     * @param time 需要格式化的时间戳
     * @return
     */
    public static String getYYMMDDHHMMP(long time) {
        SimpleDateFormat format = new SimpleDateFormat("yyyy.MM.dd HH:mm", Locale.getDefault());
        return format.format(time);
    }

    /**
     * 根据日期值得到得到年月日
     *
     * @param time
     * @return
     */
    public static String getYYMMDDL(long time) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd", Locale.getDefault());
        return sdf.format(time);
    }

    /**
     * 根据时间戳得到年月日小时分钟格式的时间
     *
     * @param time
     * @return
     */
    public static String getYYMMDDHHMML(long time) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm", Locale.getDefault());
        return sdf.format(time);
    }

    /**
     * 根据日期值得到得到年月日
     *
     * @param time
     * @return
     */
    public static String getYYMMDDX(long time) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd", Locale.getDefault());
        return sdf.format(time);
    }

    /**
     * 根据时间戳得到年月日小时分钟格式的时间
     *
     * @param time
     * @return
     */
    public static String getYYMMDDHHMMX(long time) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd HH:mm", Locale.getDefault());
        return sdf.format(time);
    }


    /**
     * 根据日期值得到星期几
     *
     * @param time
     * @return
     */
    public static String getWeek(long time) {
        SimpleDateFormat sdf = new SimpleDateFormat("EEEE", Locale.getDefault());
        String week = sdf.format(time);
        return week;
    }


    /**
     * 输入时间毫秒值算出有几天
     *
     * @param time
     * @return
     */
    public static long getDayNumber(long time) {
        long number = time / 24 / 60 / 60 / 1000;
        return number;
    }

    public static long getHourNumber(long time) {
        long number = time / 60 / 60 / 1000;
        return number;
    }

    public static long getMinuteNumber(long time) {
        long number = time / 60 / 1000;
        return number;
    }

    public static long getSecondNumber(long time) {
        long number = time / 1000;
        return number;
    }

    /**
     * 根据时间戳返回月天小时分钟
     *
     * @param date
     * @return
     */
    public static String getMMHHP(long date) {
        SimpleDateFormat format = new SimpleDateFormat("MM.dd HH:mm", Locale.getDefault());
        String time = format.format(date);
        return time;// 10-03 23:41
    }

    /**
     * 根据时间戳返回月天小时分钟
     *
     * @param date
     * @return
     */
    public static String getMMHHL(long date) {
        SimpleDateFormat format = new SimpleDateFormat("MM-dd HH:mm", Locale.getDefault());
        String time = format.format(date);
        return time;// 10-03 23:41
    }

    /**
     * 根据时间戳返回月天
     *
     * @param date
     * @return
     */
    public static String getMMDD(long date) {
        SimpleDateFormat format = new SimpleDateFormat("MM-dd", Locale.getDefault());
        String time = format.format(date);
        return time;// 10-03
    }

    /**
     * 根据时间戳返回月天
     *
     * @param date
     * @return
     */
    public static String getDDMM(long date) {
        SimpleDateFormat format = new SimpleDateFormat("dd", Locale.getDefault());
        String day = format.format(date);
        SimpleDateFormat format1 = new SimpleDateFormat("MM", Locale.getDefault());
        String mm = format1.format(date);
        return Long.valueOf(day) + "\n" + Long.valueOf(mm) + "月";// 10-03
    }

    /**
     * 根据时间戳返回月天小时分钟
     *
     * @param date
     * @return
     */
    public static String getMMHHX(long date) {
        SimpleDateFormat format = new SimpleDateFormat("MM/dd HH:mm", Locale.getDefault());
        String time = format.format(date);
        return time;// 10-03 23:41
    }


    /**
     * 返回小时分钟
     *
     * @param date
     * @return
     */
    public static String getHHMM(long date) {
        SimpleDateFormat format = new SimpleDateFormat("HH:mm", Locale.getDefault());
        String time = format.format(date);
        return time;//23:41
    }

    /**
     * 返回无间隔的时间
     *
     * @param date
     * @return
     */
    public static String getYYMMDD(long date) {
        SimpleDateFormat format = new SimpleDateFormat("yyyyMMdd", Locale.getDefault());
        String time = format.format(date);
        return time;//20151211
    }


    /**
     * 根据传入时间字符串得到毫秒值
     *
     * @param dateStr 格式  HH:mm
     * @return
     */
    public static long getHHMMByString(String dateStr) {
        if (dateStr == null || dateStr.trim().equals("")) {
            return 0;
        }
        long time = 0L;
        SimpleDateFormat format = new SimpleDateFormat("HH:mm", Locale.getDefault());
        Date date;
        try {
            date = format.parse(dateStr);
            time = date.getTime();
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return time;
    }

    /**
     * 根据传入时间字符串得到毫秒值
     *
     * @param dateStr 格式  HH:mm
     * @return
     */
    public static long getYYMMDDHHMMPByString(String dateStr) {
        if (dateStr == null || dateStr.trim().equals("")) {
            return 0;
        }
        long time = 0L;
        SimpleDateFormat format = new SimpleDateFormat("yyyy.MM.dd HH:mm", Locale.getDefault());
        Date date;
        try {
            date = format.parse(dateStr);
            time = date.getTime();
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return time;
    }

    /**
     * 根据传入时间字符串得到毫秒值
     *
     * @param dateStr 格式  HH:mm
     * @return
     */
    public static long getYYMMDDHHMMLByString(String dateStr) {
        if (dateStr == null || dateStr.trim().equals("")) {
            return 0;
        }
        long time = 0L;
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm", Locale.getDefault());
        Date date;
        try {
            date = format.parse(dateStr);
            time = date.getTime();
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return time;
    }

    /**
     * 根据传入时间字符串得到毫秒值
     *
     * @param dateStr 格式  HH:mm
     * @return
     */
    public static long getYYMMDDHHMMSSLByString(String dateStr) {
        if (dateStr == null || dateStr.trim().equals("")) {
            return 0;
        }
        long time = 0L;
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.getDefault());
        Date date;
        try {
            date = format.parse(dateStr);
            time = date.getTime();
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return time;
    }

    /**
     * 根据传入时间字符串得到毫秒值
     *
     * @param dateStr 格式  HH:mm
     * @return
     */
    public static long getYYMMDDHHMMXByString(String dateStr) {
        if (dateStr == null || dateStr.trim().equals("")) {
            return 0;
        }
        long time = 0L;
        SimpleDateFormat format = new SimpleDateFormat("yyyy/MM/dd HH:mm", Locale.getDefault());
        Date date;
        try {
            date = format.parse(dateStr);
            time = date.getTime();
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return time;
    }

    /**
     * 根据传入时间字符串得到毫秒值
     *
     * @param dateStr 格式  HH:mm
     * @return
     */
    public static long getYYMMDDPByString(String dateStr) {
        if (dateStr == null || dateStr.trim().equals("")) {
            return 0;
        }
        long time = 0L;
        SimpleDateFormat format = new SimpleDateFormat("yyyy.MM.dd", Locale.getDefault());
        Date date;
        try {
            date = format.parse(dateStr);
            time = date.getTime();
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return time;
    }

    /**
     * 根据传入date 获取字符形式的时间值
     *
     * @param date
     * @return
     */
    public static String getYYMMDDHHMMSSByDate(Date date) {
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        return format.format(date);
    }

    /**
     * 根据传入date 获取小时和分钟
     *
     * @param date
     * @return
     */
    public static String getHHMMByDate(Date date) {
        SimpleDateFormat format = new SimpleDateFormat("HH:mm");
        return format.format(date);
    }

    /**
     * 根据传入时间字符串得到毫秒值
     *
     * @param dateStr 格式  HH:mm
     * @return
     */
    public static long getYYMMDDLByString(String dateStr) {
        if (dateStr == null || dateStr.trim().equals("")) {
            return 0;
        }
        long time = 0L;
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd", Locale.getDefault());
        Date date;
        try {
            date = format.parse(dateStr);
            time = date.getTime();
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return time;
    }


    /**
     * 根据传入时间字符串得到毫秒值
     *
     * @param dateStr 格式  HH:mm
     * @return
     */
    public static long getYYMMDDXByString(String dateStr) {
        if (dateStr == null || dateStr.trim().equals("")) {
            return 0;
        }
        long time = 0L;
        SimpleDateFormat format = new SimpleDateFormat("yyyy/MM/dd", Locale.getDefault());
        Date date;
        try {
            date = format.parse(dateStr);
            time = date.getTime();
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return time;
    }

    /**
     * 根据传入时间字符串得到毫秒值
     *
     * @param dateStr 格式  HH:mm
     * @return
     */
    public static long getMMDDHHMMPByString(String dateStr) {
        if (dateStr == null || dateStr.trim().equals("")) {
            return 0;
        }
        long time = 0L;
        SimpleDateFormat format = new SimpleDateFormat("MM.dd HH:mm", Locale.getDefault());
        Date date;
        try {
            date = format.parse(dateStr);
            time = date.getTime();
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return time;
    }


    /**
     * 根据传入时间字符串得到毫秒值
     *
     * @param dateStr 格式  HH:mm
     * @return
     */
    public static long getMMDDHHMMLByString(String dateStr) {
        if (dateStr == null || dateStr.trim().equals("")) {
            return 0;
        }
        long time = 0L;
        SimpleDateFormat format = new SimpleDateFormat("MM-dd HH:mm", Locale.getDefault());
        Date date;
        try {
            date = format.parse(dateStr);
            time = date.getTime();
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return time;
    }

    /**
     * 根据传入时间字符串得到毫秒值
     *
     * @param dateStr 格式  HH:mm
     * @return
     */
    public static long getMMDDHHMMXByString(String dateStr) {
        if (dateStr == null || dateStr.trim().equals("")) {
            return 0;
        }
        long time = 0L;
        SimpleDateFormat format = new SimpleDateFormat("MM/dd HH:mm", Locale.getDefault());
        Date date;
        try {
            date = format.parse(dateStr);
            time = date.getTime();
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return time;
    }

    /**
     * date类和毫秒值的转化
     *
     * @param
     * @param
     * @return
     */
    public static Date getDateByTimeMillis(long timeMillis) {
        Date date = new Date();
        date.setTime(timeMillis);
        return date;
    }

    /**
     * 得到月的第一天
     *
     * @param calendar
     * @return
     */
    public static String getMonthFirstDayByCalender(Calendar calendar) {
        Calendar localCalendar = Calendar.getInstance();
        localCalendar.setTime(calendar.getTime());
        localCalendar.set(Calendar.DAY_OF_MONTH, 1);
        localCalendar.set(Calendar.HOUR_OF_DAY, 0);
        localCalendar.set(Calendar.MINUTE, 0);
        localCalendar.set(Calendar.SECOND, 0);
        return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.getDefault()).format(localCalendar.getTime());
    }

    /**
     * 得到月的第最后一天
     *
     * @param calendar
     * @return
     */
    public static String getMonthLastDayByCalender(Calendar calendar) {
        Calendar localCalendar = Calendar.getInstance();
        localCalendar.setTime(calendar.getTime());
        localCalendar.set(Calendar.DAY_OF_MONTH, localCalendar.getActualMaximum(Calendar.DAY_OF_MONTH));
        localCalendar.set(Calendar.HOUR_OF_DAY, 23);
        localCalendar.set(Calendar.MINUTE, 59);
        localCalendar.set(Calendar.SECOND, 59);
        return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.getDefault()).format(localCalendar.getTime());
    }

    /**
     * 得到周的第一天
     *
     * @param calendar
     * @return
     */
    public static String getFirstDayOfWeekByCalender(Calendar calendar) {
        GregorianCalendar gregorianCalendar = new GregorianCalendar();
        gregorianCalendar.setFirstDayOfWeek(Calendar.MONDAY);
        gregorianCalendar.clear();
        gregorianCalendar.setTime(calendar.getTime());
        gregorianCalendar.set(Calendar.DAY_OF_WEEK, gregorianCalendar.getFirstDayOfWeek());
        gregorianCalendar.set(Calendar.HOUR_OF_DAY, 0);
        gregorianCalendar.set(Calendar.MINUTE, 0);
        gregorianCalendar.set(Calendar.SECOND, 0);
        return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.getDefault()).format(gregorianCalendar.getTime());
    }

    /**
     * 得到周的最后一天
     *
     * @param calendar
     * @return
     */
    @SuppressLint("WrongConstant")
    public static String getLastDayOfWeekByCalender(Calendar calendar) {
        GregorianCalendar gregorianCalendar = new GregorianCalendar();
        gregorianCalendar.setFirstDayOfWeek(Calendar.MONDAY);
        gregorianCalendar.clear();
        gregorianCalendar.setTime(calendar.getTime());
        gregorianCalendar.set(Calendar.DAY_OF_WEEK, gregorianCalendar.getFirstDayOfWeek() + 6);
        gregorianCalendar.set(Calendar.HOUR_OF_DAY, 23);
        gregorianCalendar.set(Calendar.MINUTE, 59);
        gregorianCalendar.set(Calendar.SECOND, 59);
        return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.getDefault()).format(gregorianCalendar.getTime());
    }

    /**
     * 得到天的最早时刻
     *
     * @param calendar
     * @return
     */
    public static String getStartTimeOfDayByCalender(Calendar calendar) {
        GregorianCalendar gregorianCalendar = new GregorianCalendar();
        gregorianCalendar.clear();
        gregorianCalendar.setTime(calendar.getTime());
        gregorianCalendar.set(Calendar.HOUR_OF_DAY, calendar.getMinimum(Calendar.HOUR_OF_DAY));
        gregorianCalendar.set(Calendar.MINUTE, calendar.getMinimum(Calendar.MINUTE));
        gregorianCalendar.set(Calendar.SECOND, calendar.getMinimum(Calendar.SECOND));
        gregorianCalendar.set(Calendar.MILLISECOND, calendar.getMinimum(Calendar.MILLISECOND));
        return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.getDefault()).format(gregorianCalendar.getTime());
    }

    /**
     * 得到天的最晚时刻
     *
     * @param calendar
     * @return
     */
    public static String getEndTimeOfDayByCalender(Calendar calendar) {
        GregorianCalendar gregorianCalendar = new GregorianCalendar();
        gregorianCalendar.clear();
        gregorianCalendar.setTime(calendar.getTime());
        gregorianCalendar.set(Calendar.HOUR_OF_DAY, calendar.getMaximum(Calendar.HOUR_OF_DAY));
        gregorianCalendar.set(Calendar.MINUTE, calendar.getMaximum(Calendar.MINUTE));
        gregorianCalendar.set(Calendar.SECOND, calendar.getMaximum(Calendar.SECOND));
        gregorianCalendar.set(Calendar.MILLISECOND, calendar.getMaximum(Calendar.MILLISECOND));
        return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.getDefault()).format(gregorianCalendar.getTime());
    }


    /**
     * 将timeUtils中的时间格式中的"-"转化为"."
     *
     * @return time
     */
    public static String YYMMDDStyleChange(String stringTime) {
        String time = stringTime.substring(0, 4) + "." + stringTime.substring(5, 7) + "." + stringTime.substring(8, 10);
        return time;
    }

    /**
     * 将2016-11-08T12:00:00转化为2016110712
     *
     * @return time
     */
    public static String DateStyleChange(String stringTime) {
        String time = stringTime.substring(0, 4) + stringTime.substring(5, 7) + stringTime.substring(8, 10) + stringTime.substring(11, 13);
        return time;
    }

}